home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / portable / scanw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.2 KB  |  85 lines

  1. #include <stdarg.h>
  2. #include <string.h>
  3. #define    CURSES_LIBRARY    1
  4. #include <curses.h>
  5. #undef    scanw
  6.  
  7. #ifdef PDCDEBUG
  8. char *rcsid_scanw = "$Header: C:\CURSES\portable\RCS\scanw.c 2.1 1993/06/18 20:21:05 MH Rel MH $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14.  
  15. /*man-start*********************************************************************
  16.  
  17.   scanw()    - read formatted from window
  18.  
  19.   X/Open Description:
  20.      These routines correspond to scanf.  The function scanw reads
  21.      input from the default window.  The function wscanw reads
  22.      input from the specified window.  The function mvscanw moves
  23.      the cursor to the specified position and then reads input from
  24.      the default window.  The function mvwscanw moves the cursor to
  25.      the specified position and then reads input from the specified
  26.      window.
  27.  
  28.      For all the functions, the routine wgetstr is called to get a
  29.      string from the window, and the resulting line is used as
  30.      input for the scan.  All character interpretation is carried
  31.      out according to the scanf function rules.
  32.  
  33.   PDCurses Description:
  34.      The old Bjorn Larssen code for the 68K platform has been removed
  35.      from this module.
  36.  
  37.   X/Open Return Value:
  38.      Upon successful completion, the scanw, mvscanw, mvwscanw and
  39.      wscanw functions return the number of items successfully
  40.      matched.  On end-of-file, they return EOF.  Otherwise they
  41.      return ERR.
  42.  
  43.   PDCurses Errors:
  44.      No errors.
  45.  
  46.   Portability:
  47.      PDCurses    int scanw( char *fmt, ...);
  48.      X/Open Dec '88    int scanw( char *fmt, ...);
  49.      BSD Curses    int scanw( char *fmt, ...);
  50.      SYS V Curses    int scanw( char *fmt, ...);
  51.  
  52. **man-end**********************************************************************/
  53.  
  54. int    scanw(char *fmt, ...)
  55. {
  56.     va_list args;
  57.     int    retval = ERR;
  58.  
  59. #ifdef PDCDEBUG
  60.     if (trace_on) PDC_debug("scanw() - called\n");
  61. #endif
  62.  
  63. #if    !defined (HC)
  64.     if (stdscr == (WINDOW *)NULL)
  65.         return( retval );
  66.  
  67.     wrefresh(stdscr);    /* set cursor position */
  68.  
  69.     /*
  70.      * get string
  71.      */
  72.     c_printscanbuf[0] = '\0';  /* reset to empty string */
  73.     if (wgetstr(stdscr, c_printscanbuf) == ERR)
  74.         return( retval );
  75.     va_start(args, fmt);
  76. #ifdef NO_VSSCANF
  77.     retval = PDC_vsscanf(c_printscanbuf, fmt, args);
  78. #else
  79.     retval = vsscanf(c_printscanbuf, fmt, args);
  80. #endif
  81.     va_end(args);
  82. #endif
  83.     return( retval );
  84. }
  85.